<template>
  <div class="wrapper">
    <Bluetable :t-head="tHead" :t-data="tableData" @operateClick="operateClick" />
<!--    <pagination-->
<!--      :total="query.total"-->
<!--      :page.sync="query.pagenum"-->
<!--      :limit.sync="query.pagesize"-->
<!--      @pagination="getList"-->
<!--    />-->
  </div>
</template>

<script>
import { ScoreEvaluationInfo, SaveScoreEvaluationInfo } from '@/api/cpw'
export default {
  name: 'CeTable',
  data() {
    return {
      tHead: [
        {
          operate: ['修改'],
          label: '操作',
          link: true
        },
        {
          prop: 'ID',
          label: '序号'
        },
        {
          prop: 'ITEM',
          label: '评估项目'
        },
        {
          prop: 'NAME',
          label: '评估值'
        },
        {
          prop: 'SCORE',
          label: '评分'
        }
      ],
      tableData: [],
      updateData: {
        id: '',
        value: ''
      },
      query: {
        total: 100,
        page: 1,
        limit: 10
      }

    }
  },
  created() {
    this.scoreEvaluationInfo()
  },
  methods: {
    async scoreEvaluationInfo() {
      await ScoreEvaluationInfo().then(res => {
        this.tableData = res.list
      }).catch(err => {
        console.log(err)
      })
    },
    // 分页数据改变
    // async getList(type) {
    //   this.query.pagenum = type.page
    //   this.query.pagesize = type.limit
    //   await this.scoreEvaluationInfo()
    // },
    operateClick(val, row) {
      this.$prompt('请输入评分', '序号:' + row.ID, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^(-?\d+)(\.\d+)?$/,
        inputErrorMessage: '邮箱格式不正确'
      }).then(async({ value }) => {
        await SaveScoreEvaluationInfo({
          id: row.ID,
          value: value
        }).then(res => {
          console.log(res)
          if (res === 0) {
            this.$message({
              type: 'success',
              message: '你输入评分是: ' + value
            })
          } else {
            this.$message({
              message: '保存失败',
              type: 'warning'
            })
          }
          this.scoreEvaluationInfo()
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.wrapper{
  padding: 20px;
}
</style>
